/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package UTILS;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author HuuTri
 */
public class ToolOfGUI {
    /**
     * convert date to string format dd/MM/yyyy
     * @param date
     * @return 
     */
    public static String convertDateToString(Date date) {
        try {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            return format.format(date);
        } catch (Exception ex) {
            int stop = 1;
            return "";
        }
    }
    
    /**
     * convert string to date fomat dd/MM/yyyy
     * @param string
     * @return 
     */
    public static Date convertStringToDate(String string) {
        try {
            DateFormat format = new SimpleDateFormat("yyyy-MM-dd");
            return format.parse(string);
        } catch (ParseException ex) {
            Logger.getLogger(ToolOfGUI.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        } 
    }
    
    /**
     * get all first char of word of string
     * @param origin
     * @return 
     */
    public static String getFirstCharsOfString(String origin) {
        String res = "";
        String[] temp = origin.split(" ");
        if (origin.isEmpty()) return "";
        for(String tmp: temp) {
            tmp = tmp.trim();
            if (!tmp.isEmpty())
            {
                res += tmp.toUpperCase().charAt(0);
            }
        }
        
        return res;
    }
}
